﻿@inherits MasaComponentBase

<SSheetDialog EnableDomReload Value="Value" ValueChanged="SheetDialogValueChangedAsync" Title="@T("Release")" Icon="mdi-circle" IconColor="success">
    <MForm Class="full-height" Context="formContext" EnableValidation Model="_configObjectReleaseModal.Data">
        <div class="d-flex flex-column" style="width:100%; height: 100%; padding: 48px 228px">
            <div class="full-height" style="overflow-y: auto;">
                <div class="emphasis--text h6 d-flex align-center">
                    @SelectConfigObject.Name
                    <span class="ml-3 regular3--text btn">|</span>
                    <sapn class="ml-2 regular3--text btn">@SelectConfigObject.FormatLabelCode</sapn>
                </div>
                <STextField Class="mt-12" Label="@T("Release name")" Outlined @bind-Value="_configObjectReleaseModal.Data.Name"></STextField>
                <MTextarea Class="mt-6" Dense Label="@T("Description")" Outlined @bind-Value="_configObjectReleaseModal.Data.Comment"></MTextarea>
                @if (SelectConfigObject.FormatLabelCode.ToLower() == "properties")
                {
                    <p class="neutral--text" style="font-size:14px; font-weight:700;">@T("Changed configuration")</p>
                    <div style="border-radius:8px; border:1px solid #E2E7F4;" class="py-3 mt-4">
                        <MDataTable Headers="ReleaseHeaders"
                                    DisableSort
                                    TItem="ConfigObjectPropertyModel"
                                    Items="@SelectConfigObjectAllProperties"
                                    Class="table-border-none"
                                    HideDefaultFooter>
                            <HeaderColContent Context="header">
                                @if (!string.IsNullOrWhiteSpace(header.Value))
                                {
                                    <span class="regular3--text btn">@header.Text</span>
                                }
                            </HeaderColContent>
                            <ItemColContent>
                                @switch (@context.Header.Value)
                                {
                                    case nameof(ConfigObjectPropertyModel.IsPublished):
                                        if (context.Item.IsAdded)
                                        {
                                            <SIcon Color="#323D6F" Style="margin-bottom:2px;" Size="20">mdi-plus-circle</SIcon>
                                        }
                                        else if (context.Item.IsEdited || (SelectConfigObject.FromRelation && !context.Item.IsRelationed))
                                        {
                                            <SIcon Color="#323D6F" Style="margin-bottom:2px;" Size="20">mdi-pencil</SIcon>
                                        }
                                        else if (context.Item.IsDeleted)
                                        {
                                            <SIcon Color="#323D6F" Style="margin-bottom:2px;" Size="20">mdi-delete</SIcon>
                                        }
                                        break;
                                    case nameof(ConfigObjectPropertyModel.TempValue):
                                        if (context.Item.IsDeleted)
                                        {
                                            <span>@context.Item.Value</span>
                                        }
                                        else if (context.Item.IsEdited)
                                        {
                                            <span>@context.Item.TempValue</span>
                                        }
                                        break;
                                    case nameof(ConfigObjectPropertyModel.Value):
                                        if (!context.Item.IsDeleted)
                                        {
                                            <span>@context.Item.Value</span>
                                        }
                                        break;
                                    case nameof(ConfigObjectPropertyModel.ModificationTime):
                                        <DateTimeZone Value="context.Item.ModificationTime" />
                                        break;
                                    default:
                                        @context.Value
                                        break;
                                }
                            </ItemColContent>
                        </MDataTable>
                    </div>
                }
                else
                {
                    <p class="neutral--text" style="font-size:14px; font-weight:700;">@T("Released configuration")</p>
                    <MTextarea BackgroundColor="#F6F8FD" Outlined Readonly Value="@SelectConfigObject.Content"></MTextarea>
                }
            </div>
            <div class="d-flex justify-end align-end" style="width:100%;">
                <SButton Small OnClick="()=>ReleaseAsync(formContext)">@T("Release")</SButton>
            </div>
        </div>
    </MForm>
</SSheetDialog>

